import collections

# defaultdict
print()
t = "if for else while elif with not and or try expect"
d = {}
for wort in t.split(" "):
    if len(wort) in d:
        d[len(wort)].append(wort)
    else:
        d[len(wort)] = [wort]
print(d)
# Loesung mit defaultdict
t = "if for else while elif with not and or try expect"
d = collections.defaultdict(list)
for wort in t.split(" "):
    d[len(wort)].append(wort)
print(d)
print(type(d))